package cn.qqtheme.framework.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.TextView;
import cn.qqtheme.framework.util.ConvertUtils;
import java.lang.reflect.Field;

/* loaded from: classes.dex */
public class StrokeTextView extends TextView {
    private int borderColor;
    private int borderWidth;
    private boolean isStroke;
    private int textColor;
    private TextPaint textPaint;

    public StrokeTextView(Context context) {
        super(context);
        this.isStroke = false;
        this.borderWidth = 3;
        this.textColor = -1;
        this.borderColor = -16777216;
        init();
    }

    public StrokeTextView(Context context, boolean z) {
        super(context);
        this.isStroke = false;
        this.borderWidth = 3;
        this.textColor = -1;
        this.borderColor = -16777216;
        init();
        this.isStroke = z;
    }

    public StrokeTextView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.isStroke = false;
        this.borderWidth = 3;
        this.textColor = -1;
        this.borderColor = -16777216;
        init();
    }

    public StrokeTextView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.isStroke = false;
        this.borderWidth = 3;
        this.textColor = -1;
        this.borderColor = -16777216;
        init();
    }

    private void init() {
        this.textPaint = getPaint();
    }

    public void setStroke(boolean z) {
        this.isStroke = z;
        invalidate();
    }

    public void setBorderWidth(int i) {
        this.borderWidth = i;
        invalidate();
    }

    public void setBorderColor(int i) {
        this.borderColor = i;
        invalidate();
    }

    @Override // android.widget.TextView
    public void setTextColor(int i) {
        this.textColor = i;
        super.setTextColor(i);
    }

    @Override // android.widget.TextView
    public void setTextColor(ColorStateList colorStateList) {
        this.textColor = colorStateList.getColorForState(getDrawableState(), this.textColor);
        super.setTextColor(colorStateList);
    }

    @Override // android.widget.TextView, android.view.View
    protected void onDraw(Canvas canvas) {
        if (!this.isStroke) {
            super.onDraw(canvas);
            return;
        }
        int i = this.textColor;
        int i2 = this.borderColor;
        if (i == i2) {
            this.borderColor = ConvertUtils.toDarkenColor(i2, 0.7f);
        }
        setTextColorUseReflection(this.borderColor);
        this.textPaint.setStrokeWidth(ConvertUtils.toPx(getContext(), this.borderWidth));
        this.textPaint.setStyle(Paint.Style.STROKE);
        this.textPaint.setFakeBoldText(true);
        super.onDraw(canvas);
        setTextColorUseReflection(this.textColor);
        this.textPaint.setStrokeWidth(0.0f);
        this.textPaint.setStyle(Paint.Style.FILL);
        this.textPaint.setFakeBoldText(false);
        super.onDraw(canvas);
    }

    private void setTextColorUseReflection(int i) {
        try {
            Field declaredField = TextView.class.getDeclaredField("mCurTextColor");
            declaredField.setAccessible(true);
            declaredField.set(this, Integer.valueOf(i));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e2) {
            e2.printStackTrace();
        } catch (NoSuchFieldException e3) {
            e3.printStackTrace();
        }
        this.textPaint.setColor(i);
    }
}
